package lab03.test13;

import java.sql.*;

public class Test {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        // 表名字：t_students
        String sql1 = "insert into t_students(id,stu_no,real_name,age,gender,department) " +
                "values(1,'101','chen',18,'男','IS')";
        String sql2 = "insert into t_students(id,stu_no,real_name,age,gender,department) " +
                "values(2,'102','zhao',19,'男','IS')";
        String sql3 = "insert into t_students(id,stu_no,real_name,age,gender,department) " +
                "values(3,'103','qian',18,'女','IS')";
        String sql4 = "insert into t_students(id,stu_no,real_name,age,gender,department) " +
                "values(4,'104','sun',17,'女','IS')";
        String sql5 = "insert into t_students(id,stu_no,real_name,age,gender,department) " +
                "values(5,'105','li',20,'男','IS')";
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/sctu?serverTimezone=UTC",
                    "root",
                    "123456"
            );
            statement = connection.createStatement();
            resultSet=statement.executeQuery(sql1);
            resultSet=statement.executeQuery(sql2);
            resultSet=statement.executeQuery(sql3);
            resultSet=statement.executeQuery(sql4);
            resultSet=statement.executeQuery(sql5);
            while (resultSet.next()) {
                System.out.println(resultSet.getString(1) + " "
                        + resultSet.getString(2) + " "
                        + resultSet.getString(3) + " "
                        + resultSet.getString(4) + " "
                        + resultSet.getString(5));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                connection.close();
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}